var app = getApp()
Page({
  data: {
    navbar: [],
    currentTab: 0,
    navbarLen: 0,
    memos: []
  },
  navbarTap: function (e) {
    let mtid = e.target.dataset.mtid;
    if (mtid == this.data.navbar.length - 1) {
      wx.navigateTo({
        url: 'url',
      })
    }
    this.setData({
      currentTab: e.currentTarget.dataset.idx
    })
    this.getMemo(this.data.currentTab);
  },
  onLoad: function (options) {
    
    this.setData({
      uid: wx.getStorageSync('user').uid
    });

    if (this.data.uid == undefined) {
      wx.redirectTo({
          url: '../demo/index',
        }),
        wx.showToast({
          title: "请先登录！",
          icon: 'none',
          duration: 1000,
          mask: true
        })
    } else {
      let navbarLen = this.data.navbar.length;
      this.setData({
        navbarLen: navbarLen
      })
      this.getMemoType();
      this.getMemo(this.data.currentTab);
    }
  },
  //获取备忘录的类型
  getMemoType() {
    let uid = wx.getStorageSync('user').uid;
    wx.request({
      url: 'http://localhost:8080/TheTimeSequence/MemoTypeServlet?opr=list',
      data: {
        uid: uid
      },
      success: (e) => {
        this.setData({
          navbar: e.data,
        })
      }
    })
  },
  //获取备忘录
  getMemo(mtid) {
    wx.request({
      url: 'http://localhost:8080/TheTimeSequence/MemoServlet?opr=list',
      data: {
        mtid: mtid
      },
      success: (e) => {
        // console.log(e.data)
        this.setData({
          memos: e.data
        })
      }
    })
  },
  //查看备忘录详情
  memoInfo(e) {
    wx.navigateTo({
      url: '../memo/index?mid=' + e.currentTarget.dataset.mid,
    })
  },
  onShow:function(options){
    this.onLoad();
  }
})